package com.pig.controller;


import com.pig.pojo.CookBook;
import com.pig.service.ImageService;
import com.pig.service.MenuService;
import com.pig.util.JsonResult;
import com.pig.util.SysResultLayui;
import com.pig.vo.ImageVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

@RestController
public class MenuController {
    @Autowired
    private MenuService menuService;
    @Autowired
    private ImageService imageService;

    @RequestMapping("cbook/doFindObjects")
    public SysResultLayui<CookBook> doFindObjects(Integer page, Integer limit){
        return  menuService.findObject(page,limit);
        //return new JsonResult(menuService.findObject(username,pageCurrent));
    }
    @RequestMapping("cbook/doFindObjectsById")
    public JsonResult doFindObjectsById(Integer id){
        System.out.println(id);
        return new JsonResult(menuService.findObjectById(id));
    }
    @RequestMapping("cbook/doDeleteByIds")
    public JsonResult doDeleteByIds(Integer id){
        menuService.deleteObjectById(id);
        return new JsonResult("delete");
    }
    @RequestMapping("/doAddCookbook")
    public String doAddCookbook(@RequestBody CookBook cookBook){
        menuService.AddCookBook(cookBook);
        System.out.println(cookBook);
        return "sdf";
    }
    @RequestMapping("/cbook/file")
    public ImageVO file(@RequestParam("file") MultipartFile file){
        return imageService.upload(file);
    }


}
